package com.basker.pisces.concurrent.config;

import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.data.redis.core.RedisTemplate;

import com.basker.pisces.concurrent.counter.ICounterManager;
import com.basker.pisces.config.Constants;
import com.basker.pisces.redis.concurrent.lock.RedissonLockManager;
import com.basker.pisces.redis.counter.RedisCounterManager;

@Configuration
@ConditionalOnClass(RedisTemplate.class)
public class RedisCounterManagerConfiguration {

    private static final String DEFAULT_COUNTER_MANAGER = Constants.DEFAULT_COUNTER_MANAGER;

    /**
     * 如果当前存在配置redishost的属性，则默认计数器管理器为{@link RedissonLockManager}
     *
     * @return
     */
    @Bean(name = DEFAULT_COUNTER_MANAGER)
    @Primary
    public ICounterManager redisCounterManager() {
        return new RedisCounterManager(DEFAULT_COUNTER_MANAGER);
    }

}
